﻿//
// Created by francklinson on 2021/3/23.
//

#include "MyComplex.h"

MyComplex::MyComplex()
{
    re = 0;
    im = 0;
}

MyComplex::MyComplex(double a, double b)
{
    re = a;
    im = b;
}

MyComplex MyComplex::operator+(const MyComplex &m) const
{
    MyComplex sum;
    sum.re = this->re + m.re;
    sum.im = this->im + m.im;
    return sum;
}

MyComplex MyComplex::operator-(const MyComplex &m) const
{
    MyComplex sub;
    sub.re = this->re - m.re;
    sub.im = this->im - m.im;
    return sub;
}

MyComplex MyComplex::operator*(const MyComplex &m) const
{
    MyComplex mul;
    mul.re = this->re * m.re - this->im * m.im;
    mul.im = this->re * m.im + this->im * m.re;
    return mul;
}

MyComplex MyComplex::operator~() const
{
    MyComplex conj;
    conj.re = this->re;
    conj.im = -this->im;
    return conj;
}

MyComplex MyComplex::operator*(double a) const
{
    MyComplex mul;
    mul.re = this->re * a;
    mul.im = this->im * a;
    return mul;
}

MyComplex operator*(double a, MyComplex &m)
{
    return m * a;
}

std::ostream &operator<<(std::ostream &os, const MyComplex &m)
{
    std::cout << "(" << m.re << ", " << m.im << "i)";
    return os;
}

std::istream &operator>>(std::istream &is, MyComplex &m)
{
    using std::cout;
    using std::endl;
    using std::cin;
    cout << " real:";
    cin >> m.re;
    cout << " imaginary: ";
    cin >> m.im;
    return is;
}



